<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        let promise = new Promise(function (rejected, resolved) {
            console.log("Promise is created");
            throw new Error("An error occurred");
            rejected("Promise is 2");
        })
        //回调函数执行后会执行then方法
        //1.如果回调函数执行成功，then方法的第一个函数参数会被调用
        //2.如果回调函数执行失败，then方法的第二个函数参数会被调用
        //回调函数catach方法会捕获失败和异常(可以省略then方法的第二个参数)
        promise.then(function () {
            console.log("Promise is resolved");
        }).catch(function (value) {
            console.log(`Promise is ${value}`);
        });

        console.log("xxx1");
        console.log("xxx2");


    </script>
</head>

<body>

</body>

</html>